package kayao.common;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

import delayed.network.Network;
import delayed.network.OneSec;
import delayed.udp.DelayedDatagramSocket;


public class KayaoDatagramSocket {
	private DatagramSocket socket = null;
	
	public KayaoDatagramSocket(int port) throws SocketException {
		this(port, new OneSec());
	}
	
	public KayaoDatagramSocket(int port, Network network) throws SocketException {
		if (KayaoValues.DELAYED_NETWORK) {
			socket = new DelayedDatagramSocket(port, network);
		} else {
			socket = new DatagramSocket(port);
		}
	}
	
	public void send(DatagramPacket packet) throws IOException {
		socket.send(packet);
	}
	
	public void receive(DatagramPacket packet) throws IOException {
		socket.receive(packet);
	}
	
	public void close() {
		socket.close();
	}
	
	public boolean isClosed() {
		return socket.isClosed();
	}
}
